package com.jvyou.mybatis.builder.tags;

import com.jvyou.mybatis.session.Configuration;
import lombok.Data;
import org.dom4j.Element;

/**
 * @author 橘柚
 * @version 1.0-SNAPSHOT
 * @Date 2024/7/8 18:22
 * @Description 环境相关配置
 */
@Deprecated
@Data
public class EnvironmentNode implements XmlConfigNode {

    /*环境id,eg:development/test/production*/
    private String id;
    /*数据源的相关配置*/
    private DataSourceNode dataSourceNode;

    /*事务相关配置*/
    private TransactionNode transactionNode;

    /*数据源的配置节点*/
    private Element element;

    public EnvironmentNode(Element element) {
        this.element = element;
    }

    @Override
    public Configuration apply(Configuration configuration) {
        this.id = element.attributeValue("id").trim();
        // 解析事务管理器节点
        Element transactionElement = (Element) element.elements("transactionManager").get(0);
        this.transactionNode = new TransactionNode(transactionElement);
        this.transactionNode.apply(configuration);
        // 解析数据源节点
        Element dataSourceElement = (Element) element.elements("dataSource").get(0);
        this.dataSourceNode = new DataSourceNode(dataSourceElement);
        this.dataSourceNode.apply(configuration);
        configuration.setEnvironmentNode(this);
        return configuration;
    }
}
